﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Collections.Generic;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    
    public partial class TWDI2PR
    {

        public TWDI2PR()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VWDECK();
            this.DataContext = MV;
            InitializeComponent(); 
        }
          
        public override void NewCommand(object sender, RoutedEventArgs e)
        {
            if (QTY == 0)
                return; 
            DI2PR(dwWD);
            base.NewCommand(sender, e);
        }
        public void DI2PR(DataRow dwWD)
        {
           
            //根据当前的需求，创建细纱单，注意，这个最好直接执行，因为可能存在多个需求，要逐个创建，
            //比如AB纱
            try
            {
                if (dwWD == null)
                {
                    throw new Exception("请选择一行！");
                }
                KRS = "P" + dwWD["WDAUFKRS"].ToString().Substring(1);
                PM["KRS"] = KRS;
                PM["LFD"] = dwWD["WDAUFLFD"].ToString();
                PM["AUFART"] = "PR";
                PM["ORDERNUM"] = dwWD["ABKKDAUFTNR"].ToString();
                TMV.VABK.LOAD(PM);
                PM["DELDATE"] = dwWD["WDDAT"];

                PM["QTYEND"] = QTY;//这句话，之前是否也是隐藏的》之前是有的 
                PM["CART"] = dwWD["WDART"].ToString() + dwWD["WDVAR"].ToString() + dwWD["WDFARBE"].ToString();
                POS = VSDDAT.SD22.GETNEXT("0022", KRS, dwWD["WDAUFLFD"].ToString(), 1);
                POS=Helpers.Helper.Right(POS, 3);
                PM["ORDERNUM"] = KRS + dwWD["WDAUFLFD"].ToString() + POS + "PR ";
                PM["COLOR"] = "PR ";
                PM["AUFTYP"] = "V";
                PM["ARTSTAGE"] = "Z";
                //PM["VKAUF"] = pm["ORDERNUM"];
                PM["VKPAUF"] = dwWD["ABKKDAUFTNR"].ToString();
                PM["VKPQTY"] =QTY;//若按你
                PM["VKAUF"] = dwWD["WDAUFKRS"].ToString() + dwWD["WDAUFLFD"].ToString() + dwWD["WDAUFPOS"].ToString() + dwWD["WDUPOS"].ToString() + "V";//若按你
                TMV.VPR.NEWPLAN(PM);

                MessageInfo msg = new MessageInfo();
                msg.Sender = RUNID;
                msg.MSGTYPE = "DI2PR";
                msg.ACTION = "DI2PR";
                msg.AUFTYP = "V";
                msg.WAKZ = dwWD["WDWAKZ"].ToString();
                msg.ART = dwWD["WDART"].ToString();
                msg.VAR = dwWD["WDVAR"].ToString();
                msg.FARBE = dwWD["WDFARBE"].ToString();
                msg.KRS = dwWD["WDAUFKRS"].ToString();
                msg.LFD = dwWD["WDAUFLFD"].ToString();
                msg.POS = dwWD["WDAUFPOS"].ToString();
                msg.P1 = dwWD["WDUPOS"].ToString();
                msg.P2 = dwWD["WDSA"].ToString();
                msg.ORDER = (string)PM["ORDERNUM"];
                msg.Where = app.User;
                VICC_WFEVENTS.SVWF.CheckEvents("UIMESSAGE", null, "", msg);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

    }
     
}
